home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / hash.zip / LIST.5 < prev    next >
Text File  |  1993-01-04  |  1KB  |  35 lines

  1. 100 'Routine to do a table look-up using chained hashing
  2. 110 '
  3. 120 'TB = table of names to be entered/looked up.
  4. 130 'CH = table of chain pointers
  5. 140 'IX = index to entry of TB where the name was entered or found
  6. 150 'OV = pointer to the last entry used in the overflow table
  7. 160 'FD = flag reporting result of search: 0=not found, 1=found
  8. 170 'K$ = holds the current KEY being searched for
  9. 180 'MT = maximum total table size (primary and secondary)
  10. 190 '
  11. 200 FD = 0  'initialize result of search to "not found"
  12. 210 GOSUB 1000 'go hash the key in K$; the result is returned in IX
  13. 220 '
  14. 230 'examine first entry with correct hash value
  15. 240 '
  16. 250 IF TB(IX) = "" THEN TB(IX) = K$: RETURN 'it's empty - enter KEY and return
  17. 260 IF TB(IX) = K$ THEN FD = 1: RETURN  'found it - say so and return
  18. 270 '
  19. 280 'the first entry had some name other than KEY in it - step down the chain
  20. 290 '
  21. 300 IF CH(IX) <> 0 THEN IX = CH(IX): GOTO 260 'step down the chain
  22. 310 '
  23. 320 'We found the end of the chain,  so enter the key and return with FD = 0
  24. 330 '
  25. 340 OV = OV + 1  'advance to next empty overflow entry
  26. 350 IF OV > MT THEN GOTO 2000 'goto the error routine and never return
  27. 360 TB(OV) = K$   'enter KEY
  28. 370 CH(IX) = OV   'and add the new entry to the end of the chain
  29. 380 IX = OV       'set IX to tell the caller where we entered it
  30. 390 '
  31. 400 RETURN
  32.  
  33.  
  34.  
  35.